package com.wilson.integration.lease.admin.controller.apartment;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wilson.integration.lease.admin.service.RoomInfoService;
import com.wilson.integration.lease.common.result.Result;
import com.wilson.integration.lease.common.entity.RoomInfo;
import com.wilson.integration.lease.common.enums.ReleaseStatus;
import com.wilson.integration.lease.common.entity.vo.room.RoomDetailVO;
import com.wilson.integration.lease.common.entity.vo.room.RoomItemVO;
import com.wilson.integration.lease.common.entity.vo.room.RoomQueryVO;
import com.wilson.integration.lease.common.entity.vo.room.RoomSubmitVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "房间信息管理")
@RestController
@RequestMapping("/admin/room")
public class RoomController {

    @Resource
    private RoomInfoService roomInfoService;

    @Operation(summary = "保存或更新房间信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoomSubmitVO roomSubmitVO) {
        roomInfoService.saveOrUpdateRoom(roomSubmitVO);
        return Result.ok();
    }

    @Operation(summary = "根据条件分页查询房间列表")
    @GetMapping("pageItem")
    public Result<IPage<RoomItemVO>> pageItem(@RequestParam long current, @RequestParam long size, RoomQueryVO queryVO) {
        IPage<RoomItemVO> page = new Page<>(current, size);
        return Result.ok(roomInfoService.pageRoomItemByQuery(page, queryVO));
    }

    @Operation(summary = "根据id获取房间详细信息")
    @GetMapping("getDetailById")
    public Result<RoomDetailVO> getDetailById(@RequestParam Long id) {
        return Result.ok(roomInfoService.getRoomDetailById(id));
    }

    @Operation(summary = "根据id删除房间信息")
    @DeleteMapping("removeById")
    public Result removeById(@RequestParam Long id) {
        roomInfoService.removeRoomById(id);
        return Result.ok();
    }

    @Operation(summary = "根据id修改房间发布状态")
    @PostMapping("updateReleaseStatusById")
    public Result updateReleaseStatusById(Long id, ReleaseStatus status) {
        roomInfoService.update(
                new LambdaUpdateWrapper<RoomInfo>()
                        .eq(RoomInfo::getId, id)
                        .set(RoomInfo::getIsRelease, status));
        return Result.ok();
    }

    @GetMapping("listBasicByApartmentId")
    @Operation(summary = "根据公寓id查询房间列表")
    public Result<List<RoomInfo>> listBasicByApartmentId(Long id) {
        List<RoomInfo> roomInfoList = roomInfoService.list(
                new LambdaQueryWrapper<RoomInfo>()
                        .eq(RoomInfo::getApartmentId, id)
                        .eq(RoomInfo::getIsRelease, ReleaseStatus.RELEASED));
        return Result.ok(roomInfoList);
    }

}


















